﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace A2DFramework.SQLDispatcherService.Context
{
    public class SQLDispatcherContext
    {
        public string Region { get; set; }

        public static SQLDispatcherContext GetCurrentContext()
        {
            SQLDispatcherContext ctx = null;
            if (HttpContext.Current != null)
                ctx = (SQLDispatcherContext)HttpContext.Current.Items["SQLDispatcherContext"];
            else
                ctx = (SQLDispatcherContext)HttpRuntime.Cache["SQLDispatcherContext"];
            return ctx ?? new SQLDispatcherContext() {  Region=string.Empty};
        }
        public static void SetCurrentContext(SQLDispatcherContext ctx)
        {
            if (HttpContext.Current != null)
                HttpContext.Current.Items["SQLDispatcherContext"]=ctx;
            else
                HttpRuntime.Cache["SQLDispatcherContext"]=ctx;
        }

        public static void ResetCurrentContext()
        {
            SQLDispatcherContext ctx = new SQLDispatcherContext();
            ctx.Region = string.Empty;
            SetCurrentContext(ctx);
        }
    }
}
